package org.example.jiap.bk.controller;

import org.example.jiap.bk.model.pojo.JiapUserPOJO;
import org.example.jiap.bk.model.pojo.ResultPOJO;
import org.example.jiap.bk.service.JiapUserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/bk")
public class JiapUserController {
    @Resource
    private JiapUserService jiapUserService;

    @PostMapping("/register")
    public ResultPOJO register(@RequestBody JiapUserPOJO jiapUserPOJO) throws Exception {
        int rtnCode = jiapUserService.register(jiapUserPOJO);
        //rtnCode = jiapUserService.register(jiapUserPOJO);
        System.out.println("JiapUserPOJO" + jiapUserPOJO.getUserName());
        if (rtnCode == 0) {
            return ResultPOJO.success();
        } else {
            return ResultPOJO.error("用户已经注册");
        }
    }

    @PostMapping("/login")
    public void login(@RequestBody JiapUserPOJO jiapUserPOJO) throws Exception {
        jiapUserService.login(jiapUserPOJO);
    }

    @PostMapping("/refresh")
    public void refresh(@RequestBody JiapUserPOJO jiapUserPOJO) throws Exception {
        jiapUserService.refresh(jiapUserPOJO);
    }

    @PostMapping("/querry")
    public void querry(@RequestBody JiapUserPOJO jiapUserPOJO) throws Exception {
        jiapUserService.querry(jiapUserPOJO);
    }

    @PostMapping("/querrymix")
    public void querrymix(@RequestBody JiapUserPOJO jiapUserPOJO) throws Exception {
        jiapUserService.querrymix(jiapUserPOJO);
    }
}

